package com.fishing.controller;

import QL.*;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.fishing.service.GamePictureService;
import com.fishing.util.personal.RegExrUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller
public class GameController {
    
	private static QLClient client = new QLClient();
	
	@Autowired
	private GamePictureService gamePictureService;
	@Autowired
	
	//region 跳转平台网页
	@RequestMapping(value="game/platform")
	public ModelAndView platform(HttpServletRequest request) {
		ModelAndView mav = new  ModelAndView("game/platform");
		return mav;
	}
	//endregion
	
	//region 跳转到修改平台水位网页
	@RequestMapping(value="platform/changewater")
	public ModelAndView changewater(HttpServletRequest request) {
		ModelAndView mav = new  ModelAndView("game/changewater");
		return mav;
	}
	//endregion
	
	//region 跳转到修改平台水位线网页
	@RequestMapping(value="platform/changewaterline")
	public ModelAndView changewaterline(HttpServletRequest request) {
		ModelAndView mav = new  ModelAndView("game/changewaterline");
		return mav;
	}
	//endregion
	
	//region 跳转到修改平台分红水位线网页
	@RequestMapping(value="platform/sharebonuswaterline")
	public ModelAndView sharebonuswaterline(HttpServletRequest request) {
		ModelAndView mav = new  ModelAndView("game/sharebonuswaterline");
		return mav;
	}
	//endregion
	
	//region 跳转到抽水统计页面
	@RequestMapping(value="game/Pumpingstatistics")
	public ModelAndView Pumpingstatistics(HttpServletRequest request) {
		ModelAndView mav = new  ModelAndView("game/pumpingstatistics");
		return mav;
	}
	//endregion

	//region 跳转到分红设置页面
	@RequestMapping(value="game/Bonussettings")
	public ModelAndView Bonussettings(HttpServletRequest request) {
		ModelAndView mav = new  ModelAndView("game/bonussettings");
		return mav;
	}
	//endregion

	//region 跳转到设置抽水间隔页面
	@RequestMapping(value="platform/changepumptimeview")
	public ModelAndView changepumptimeview(HttpServletRequest request) {
		ModelAndView mav = new  ModelAndView("game/changepumptimeview");
		return mav;
	}
	//endregion
	
	//region 跳转到设置分红间隔页面
	@RequestMapping(value="platform/changebonustimeview")
	public ModelAndView changebonustimeview(HttpServletRequest request) {
		ModelAndView mav = new  ModelAndView("game/changebonustimeview");
		return mav;
	}
	//endregion

	//region 跳转到设置抽水比例页面
	@RequestMapping(value="platform/changepumpproportionview")
	public ModelAndView changepumpproportionview(HttpServletRequest request) {
		ModelAndView mav = new  ModelAndView("game/changepumpproportionview");
		return mav;
	}
	//endregion
	
	//region 跳转到设置分红比例页面
	@RequestMapping(value="platform/changebonusproportionview")
	public ModelAndView changebonusproportionview(HttpServletRequest request) {
		ModelAndView mav = new  ModelAndView("game/changebonusproportionview");
		return mav;
	}
	//endregion

	//region 跳转到临时奖池比例页面
	@RequestMapping(value="platform/changetemporaryview")
	public ModelAndView changetemporaryview(HttpServletRequest request) {
		ModelAndView mav = new  ModelAndView("game/changetemporaryview");
		return mav;
	}
	//endregion
	
	//region 跳转到临时奖池比例页面
	@RequestMapping(value="game/switchsettingview")
	public ModelAndView switchsetting(HttpServletRequest request) {
		ModelAndView mav = new  ModelAndView("game/switchsettingview");
		return mav;
	}
	//endregion
	
	//region 平台水位表展示
	@ResponseBody
	@RequestMapping(value="platform/list", method = RequestMethod.POST, produces="text/html;charset=UTF-8")
	public Map<String,Object> list (HttpServletRequest request) {
		//定义Map,list 作为返回变量值
		Map<String,Object> map = new HashMap<String, Object>();
		List<Object> list = new ArrayList<Object>();
		//region 请求全局信息
		ButlerGetGlobalInfomationRequest req = new ButlerGetGlobalInfomationRequest();
		req.ZoneId = (Integer)request.getSession().getAttribute("ZoneId");
		ButlerGetGlobalInfomationResponse rsp = new ButlerGetGlobalInfomationResponse();
		if (req.ZoneId < 0)
			client.ServerUrl = "http://api2.qq1798.com:8000/router/rest";
		client.Execute(req, rsp);
		//endregion
		
		//region 返回水位列表
		if (rsp.ErrMsg == "" || rsp.ErrMsg == null) {
			Map<String,Object> mapdata = new HashMap<String, Object>();
			mapdata.put("GlobalPrizePool", rsp.GlobalPrizePool);
			mapdata.put("GlobalGameDifficultyLevel", rsp.GlobalGameDifficultyLevel);
			mapdata.put("PrizePoolAutoFetchCD", rsp.PrizePoolAutoFetchCD);
			mapdata.put("PrizePoolAutoFetchRate", rsp.PrizePoolAutoFetchRate);
			mapdata.put("PrizePoolNextAutoFetchTime", rsp.PrizePoolNextAutoFetchTime);
			mapdata.put("PrizePoolAutoFetchBoundary", rsp.PrizePoolAutoFetchBoundary);
			list.add(mapdata);
			map.put("status", "200");
			map.put("message", "");
			map.put("count", 0);
			map.put("data", list);
			return map;
		} else {
			map.put("status", "200");
			map.put("message", "");
			map.put("count", 0);
			map.put("data", 0);
			return map;
		}
		//endregion
	}
	//endregion
    
	//region 水位修改
	@ResponseBody
	@RequestMapping(value="waterline/Setvalue", method = RequestMethod.POST, produces="text/html;charset=UTF-8")
	public String Setvalue(HttpServletRequest request, String waterLine)  {
		//检测前台传入的值是否合法
		if (!RegExrUtils.isNumber(waterLine)) 
			return "请输入纯数字";
		
		//修改水位
		ButlerPrizePoolWaterLineAddRequest req = new ButlerPrizePoolWaterLineAddRequest();
		req.ZoneId = (Integer)request.getSession().getAttribute("ZoneId");
		req.Delta = Long.valueOf(waterLine);
		req.Operater = (String)request.getSession().getAttribute("Admintruename");
		ButlerPrizePoolWaterLineAddResponse rsp = new ButlerPrizePoolWaterLineAddResponse();
		if (req.ZoneId < 0)
			client.ServerUrl = "http://api2.qq1798.com:8000/router/rest";
		client.Execute(req, rsp);
		
		//处理返回值
		if (rsp.ErrMsg == "" || rsp.ErrMsg == null) 
			return "success";
		else
			return rsp.ErrMsg;
	}
	//endregion

	//region 立刻分红
	@ResponseBody
	@RequestMapping(value="platform/immediately", method = RequestMethod.POST, produces="text/html;charset=UTF-8")
	public String immediately(HttpServletRequest request)  {
		//发送请求
		ButlerPrizePoolShareBonusImmediateRequest req = new ButlerPrizePoolShareBonusImmediateRequest();
		req.ZoneId = (Integer)request.getSession().getAttribute("ZoneId");
		ButlerPrizePoolShareBonusImmediateResponse rsp = new ButlerPrizePoolShareBonusImmediateResponse();
		if (req.ZoneId < 0)
			client.ServerUrl = "http://api2.qq1798.com:8000/router/rest";
		client.Execute(req, rsp);
		
		//返回错误代码
		//处理返回值
		if (rsp.ErrMsg == "" || rsp.ErrMsg == null) 
			return "success";
		else
			return rsp.ErrMsg;
	}
	//endregion

	//region 水位统计显示
	@ResponseBody
    @RequestMapping(value="Statistics/list",method = RequestMethod.POST,produces="text/html;charset=UTF-8")
    public Map<String,Object> list(HttpServletRequest request,String ContentType,String StartTime,String EndTime,String PageIndex,String PageCount) {
		ButlerPrizePoolWaterLineLogQueryRequest req = new ButlerPrizePoolWaterLineLogQueryRequest();
		ButlerPrizePoolWaterLineLogQueryResponse rsp = new ButlerPrizePoolWaterLineLogQueryResponse();
		Map<String,Object> map = new HashMap<String, Object>();
		//检测是否按时间来查询
		if (("").equals(StartTime) && ("").equals(EndTime)) {
			req.ZoneId = (Integer)request.getSession().getAttribute("ZoneId");
			req.PageIndex = Integer.parseInt(PageIndex) - 1;
			req.PageCount = Integer.parseInt(PageCount);
			req.IsFilterDateTime = false;
			req.FilterState = Integer.parseInt(ContentType);
			//发送协议
			if (req.ZoneId < 0)
				client.ServerUrl = "http://api2.qq1798.com:8000/router/rest";
			client.Execute(req, rsp);
			map.put("status", "200");
			map.put("message", "");
			map.put("count", rsp.TotalCount);
			map.put("data", rsp.LogList);
			return map;
		}else {
			req.ZoneId = (Integer)request.getSession().getAttribute("ZoneId");
			req.PageIndex = Integer.parseInt(PageIndex) - 1;
			req.PageCount = Integer.parseInt(PageCount);
			req.IsFilterDateTime = true;
			req.FilterBeginTime = StartTime;
			req.FilterEndTime = EndTime;
			req.FilterState = Integer.parseInt(ContentType);
			if (req.ZoneId < 0)
				client.ServerUrl = "http://api2.qq1798.com:8000/router/rest";
			client.Execute(req, rsp);
			map.put("status", "200");
			map.put("message", "");
			map.put("count", rsp.TotalCount);
			map.put("data", rsp.LogList);
			return map;
		}
	}
	//endregion

	//region 抽放水统计次数
	@ResponseBody
    @RequestMapping(value="DailyStatistics/listDetail",method = RequestMethod.POST,produces="text/html;charset=UTF-8")
	public Map<String,Object> listDetail(HttpServletRequest request, String PageIndex, String PageCount) {
		ButlerPrizePoolWaterLineDailyStatRequest req = new ButlerPrizePoolWaterLineDailyStatRequest();
		ButlerPrizePoolWaterLineDailyStatResponse rsp = new ButlerPrizePoolWaterLineDailyStatResponse();
		Map<String,Object> map = new HashMap<String, Object>();
		//发送协议
		req.ZoneId = (Integer)request.getSession().getAttribute("ZoneId");
		req.PageIndex = Integer.parseInt(PageIndex) - 1;
		req.PageCount = Integer.parseInt(PageCount);
		if (req.ZoneId < 0)
			client.ServerUrl = "http://api2.qq1798.com:8000/router/rest";
		client.Execute(req, rsp);
		//返回值处理
		if (rsp.ErrMsg == "" || rsp.ErrMsg == null) {
			map.put("status", "200");
			map.put("message", "");
			map.put("count", rsp.TotalCount);
			map.put("data", rsp.StatItems);
			return map;
		}else {
			map.put("status", "200");
			map.put("message", "");
			map.put("count", 0);
			map.put("data", 0);
			return map;
		}
	}
	//endregion

	//region 平台水位表展示
	@ResponseBody
	@RequestMapping(value="platform/Bonussettingslist", method = RequestMethod.POST, produces="text/html;charset=UTF-8")
	public Map<String,Object> Bonussettingslist (HttpServletRequest request) {
		//定义Map,list 作为返回变量值
		Map<String,Object> map = new HashMap<String, Object>();
		List<Object> list = new ArrayList<Object>();
		//region 请求全局信息
		ButlerGetGlobalInfomationRequest req = new ButlerGetGlobalInfomationRequest();
		req.ZoneId = (Integer)request.getSession().getAttribute("ZoneId");
		ButlerGetGlobalInfomationResponse rsp = new ButlerGetGlobalInfomationResponse();
		if (req.ZoneId < 0)
			client.ServerUrl = "http://api2.qq1798.com:8000/router/rest";
		client.Execute(req, rsp);
		//endregion
		
		//region 返回水位列表
		if (rsp.ErrMsg == "" || rsp.ErrMsg == null) {
			Map<String,Object> mapdata = new HashMap<String, Object>();
			mapdata.put("GlobalPrizePool", rsp.GlobalPrizePool);
			mapdata.put("GlobalGameDifficultyLevel", rsp.GlobalGameDifficultyLevel);
			mapdata.put("PrizePoolShareBonusBoundary", rsp.PrizePoolShareBonusBoundary);
			mapdata.put("PrizePoolShareBonusRate", rsp.PrizePoolShareBonusRate);
			mapdata.put("PrizePoolShareBonusAdditionRate", rsp.PrizePoolShareBonusAdditionRate);
			mapdata.put("PrizePoolShareBonusCD", rsp.PrizePoolShareBonusCD);
			mapdata.put("PrizePoolNextShareBonusTime", rsp.PrizePoolNextShareBonusTime);
			mapdata.put("PrizePoolDifficultyBoundary", rsp.PrizePoolDifficultyBoundary);
			mapdata.put("PrizePoolAutoFetchBoundary", rsp.PrizePoolAutoFetchBoundary);
			list.add(mapdata);
			map.put("status", "200");
			map.put("message", "");
			map.put("count", 0);
			map.put("data", list);
			return map;
		} else {
			map.put("status", "200");
			map.put("message", "");
			map.put("count", 0);
			map.put("data", 0);
			return map;
		}
		//endregion
	}
	//endregion

	
	//region 修改抽水线
	@ResponseBody
	@RequestMapping(value="waterline/SetWaterlinevalue", method = RequestMethod.POST, produces="text/html;charset=UTF-8")
	public String SetWaterlinevalue (HttpServletRequest request  ,String waterLine) {
		
		//region 后台安全检测
		if (Long.valueOf(waterLine) < 1) 
			return "修改水位线最低为1";
		try {
			ButlerExcelFieldGetRequest req = new ButlerExcelFieldGetRequest();
			req.ZoneId = (Integer)request.getSession().getAttribute("ZoneId");
			req.FieldString = "[[\"Platform/Global.xlsx\",1,\"PrizePoolAutoFetchBoundary\"]]";
			ButlerExcelFieldGetResponse rsp = new ButlerExcelFieldGetResponse();
			if (req.ZoneId < 0)
				client.ServerUrl = "http://api2.qq1798.com:8000/router/rest";
			client.Execute(req, rsp);
			if (!(rsp.ErrMsg ==  null || rsp.ErrMsg == "")) 
				return "获取值错误 ";
		} catch (Exception e) {
			e.printStackTrace();
		}
		//endregion
		//region 设置值
		ButlerExcelFieldSetRequest req = new ButlerExcelFieldSetRequest();
		req.ZoneId = (Integer)request.getSession().getAttribute("ZoneId");
		req.FieldString = "[[\"Platform/Global.xlsx\",1,\"PrizePoolAutoFetchBoundary\"," + waterLine + "]]";
		ButlerExcelFieldSetResponse rsp = new ButlerExcelFieldSetResponse();
		if (req.ZoneId < 0)
			client.ServerUrl = "http://api2.qq1798.com:8000/router/rest";
		client.Execute(req, rsp);
		if (rsp.ErrMsg ==  null || rsp.ErrMsg == "")
			return "success";
		else
			return rsp.ErrMsg;
		//endregion
	}
	//endregion
	
	//region 修改分红水位线
	@ResponseBody
	@RequestMapping(value="sharepool/Setsharebonuswaterline", method = RequestMethod.POST, produces="text/html;charset=UTF-8")
	public String Setsharebonuswaterline (HttpServletRequest request  ,String waterLine) {
		
		//region 后台安全检测
		if (Long.valueOf(waterLine) < 1) 
			return "修改分红水位线最低为1";
		try {
			ButlerExcelFieldGetRequest req = new ButlerExcelFieldGetRequest();
			req.ZoneId = (Integer)request.getSession().getAttribute("ZoneId");
			req.FieldString = "[[\"Platform/Global.xlsx\",1,\"PrizePoolShareBonusBoundary\"]]";
			ButlerExcelFieldGetResponse rsp = new ButlerExcelFieldGetResponse();
			if (req.ZoneId < 0)
				client.ServerUrl = "http://api2.qq1798.com:8000/router/rest";
			client.Execute(req, rsp);
			if (!(rsp.ErrMsg ==  null || rsp.ErrMsg == "")) 
				return "获取值错误 ";
		} catch (Exception e) {
			e.printStackTrace();
		}
		//endregion
		//region 设置值
		ButlerExcelFieldSetRequest req = new ButlerExcelFieldSetRequest();
		req.ZoneId = (Integer)request.getSession().getAttribute("ZoneId");
		req.FieldString = "[[\"Platform/Global.xlsx\",1,\"PrizePoolShareBonusBoundary\"," + waterLine + "]]";
		ButlerExcelFieldSetResponse rsp = new ButlerExcelFieldSetResponse();
		if (req.ZoneId < 0)
			client.ServerUrl = "http://api2.qq1798.com:8000/router/rest";
		client.Execute(req, rsp);
		if (rsp.ErrMsg ==  null || rsp.ErrMsg == "")
			return "success";
		else
			return rsp.ErrMsg;
		//endregion
	}
	//endregion

	//region 修改抽水间隔(分钟)
	@ResponseBody
	@RequestMapping(value="platform/changepumptime", method = RequestMethod.POST, produces="text/html;charset=UTF-8")
	public String changepumptime (HttpServletRequest request  ,String time) {
		
		//region 后台安全检测
		if (Integer.parseInt(time) < 1) 
			return "修改抽水间隔要大于1分钟";
		try {
			ButlerExcelFieldGetRequest req = new ButlerExcelFieldGetRequest();
			req.ZoneId = (Integer)request.getSession().getAttribute("ZoneId");
			req.FieldString = "[[\"Platform/Global.xlsx\",1,\"PrizePoolAutoFetchCD\"]]";
			ButlerExcelFieldGetResponse rsp = new ButlerExcelFieldGetResponse();
			if (req.ZoneId < 0)
				client.ServerUrl = "http://api2.qq1798.com:8000/router/rest";
			client.Execute(req, rsp);
			if (!(rsp.ErrMsg ==  null || rsp.ErrMsg == "")) 
				return "获取值错误 ";
		} catch (Exception e) {
			e.printStackTrace();
		}
		//endregion
		//region 设置值
		ButlerExcelFieldSetRequest req = new ButlerExcelFieldSetRequest();
		req.ZoneId = (Integer)request.getSession().getAttribute("ZoneId");
		req.FieldString = "[[\"Platform/Global.xlsx\",1,\"PrizePoolAutoFetchCD\"," + Integer.parseInt(time)*60 + "]]";
		ButlerExcelFieldSetResponse rsp = new ButlerExcelFieldSetResponse();
		if (req.ZoneId < 0)
			client.ServerUrl = "http://api2.qq1798.com:8000/router/rest";
		client.Execute(req, rsp);
		if (rsp.ErrMsg ==  null || rsp.ErrMsg == "")
			return "success";
		else
			return rsp.ErrMsg;
		//endregion
	}
	//endregion
	
	//region 修改抽水间隔(分钟)
	@ResponseBody
	@RequestMapping(value="platform/changebonustime", method = RequestMethod.POST, produces="text/html;charset=UTF-8")
	public String changebonustime (HttpServletRequest request  ,String time) {
		
		//region 后台安全检测
		if (Integer.parseInt(time) < 1) 
			return "修改分红间隔要大于1分钟";
		try {
			ButlerExcelFieldGetRequest req = new ButlerExcelFieldGetRequest();
			req.ZoneId = (Integer)request.getSession().getAttribute("ZoneId");
			req.FieldString = "[[\"Platform/Global.xlsx\",1,\"PrizePoolShareBonusCD\"]]";
			ButlerExcelFieldGetResponse rsp = new ButlerExcelFieldGetResponse();
			if (req.ZoneId < 0)
				client.ServerUrl = "http://api2.qq1798.com:8000/router/rest";
			client.Execute(req, rsp);
			if (!(rsp.ErrMsg ==  null || rsp.ErrMsg == "")) 
				return "获取值错误 ";
		} catch (Exception e) {
			e.printStackTrace();
		}
		//endregion
		//region 设置值
		ButlerExcelFieldSetRequest req = new ButlerExcelFieldSetRequest();
		req.ZoneId = (Integer)request.getSession().getAttribute("ZoneId");
		req.FieldString = "[[\"Platform/Global.xlsx\",1,\"PrizePoolShareBonusCD\"," + Integer.parseInt(time)*60 + "]]";
		ButlerExcelFieldSetResponse rsp = new ButlerExcelFieldSetResponse();
		if (req.ZoneId < 0)
			client.ServerUrl = "http://api2.qq1798.com:8000/router/rest";
		client.Execute(req, rsp);
		if (rsp.ErrMsg ==  null || rsp.ErrMsg == "")
			return "success";
		else
			return rsp.ErrMsg;
		//endregion
	}
	//endregion
	
	//region 修改抽水间隔(分钟)
	@ResponseBody
	@RequestMapping(value="platform/changepumpproportion", method = RequestMethod.POST, produces="text/html;charset=UTF-8")
	public String changepumpproportion (HttpServletRequest request  ,String proportion) {
		
		//region 后台安全检测
		if (Double.valueOf(proportion) < 0) 
			return "修改抽水比例大于0";
		try {
			ButlerExcelFieldGetRequest req = new ButlerExcelFieldGetRequest();
			req.ZoneId = (Integer)request.getSession().getAttribute("ZoneId");
			req.FieldString = "[[\"Platform/Global.xlsx\",1,\"PrizePoolAutoFetchRate\"]]";
			ButlerExcelFieldGetResponse rsp = new ButlerExcelFieldGetResponse();
			if (req.ZoneId < 0)
				client.ServerUrl = "http://api2.qq1798.com:8000/router/rest";
			client.Execute(req, rsp);
			if (!(rsp.ErrMsg ==  null || rsp.ErrMsg == "")) 
				return "获取值错误 ";
		} catch (Exception e) {
			e.printStackTrace();
		}
		//endregion
		//region 设置值
		ButlerExcelFieldSetRequest req = new ButlerExcelFieldSetRequest();
		req.ZoneId = (Integer)request.getSession().getAttribute("ZoneId");
		req.FieldString = "[[\"Platform/Global.xlsx\",1,\"PrizePoolAutoFetchRate\"," + proportion + "]]";
		ButlerExcelFieldSetResponse rsp = new ButlerExcelFieldSetResponse();
		if (req.ZoneId < 0)
			client.ServerUrl = "http://api2.qq1798.com:8000/router/rest";
		client.Execute(req, rsp);
		if (rsp.ErrMsg ==  null || rsp.ErrMsg == "")
			return "success";
		else
			return rsp.ErrMsg;
		//endregion
	}
	//endregion
	
	//region 修改分红间隔(分钟)
	@ResponseBody
	@RequestMapping(value="platform/changebonusproportion", method = RequestMethod.POST, produces="text/html;charset=UTF-8")
	public String changebonusproportion (HttpServletRequest request  ,String proportion) {
		
		//region 后台安全检测
		if (Double.valueOf(proportion) < 0) 
			return "修改分红比例大于0";
		try {
			ButlerExcelFieldGetRequest req = new ButlerExcelFieldGetRequest();
			req.ZoneId = (Integer)request.getSession().getAttribute("ZoneId");
			req.FieldString = "[[\"Platform/Global.xlsx\",1,\"PrizePoolShareBonusRate\"]]";
			ButlerExcelFieldGetResponse rsp = new ButlerExcelFieldGetResponse();
			if (req.ZoneId < 0)
				client.ServerUrl = "http://api2.qq1798.com:8000/router/rest";
			client.Execute(req, rsp);
			if (!(rsp.ErrMsg ==  null || rsp.ErrMsg == "")) 
				return "获取值错误 ";
		} catch (Exception e) {
			e.printStackTrace();
		}
		//endregion
		//region 设置值
		ButlerExcelFieldSetRequest req = new ButlerExcelFieldSetRequest();
		req.ZoneId = (Integer)request.getSession().getAttribute("ZoneId");
		req.FieldString = "[[\"Platform/Global.xlsx\",1,\"PrizePoolShareBonusRate\"," + proportion + "]]";
		ButlerExcelFieldSetResponse rsp = new ButlerExcelFieldSetResponse();
		if (req.ZoneId < 0)
			client.ServerUrl = "http://api2.qq1798.com:8000/router/rest";
		client.Execute(req, rsp);
		if (rsp.ErrMsg ==  null || rsp.ErrMsg == "")
			return "success";
		else
			return rsp.ErrMsg;
		//endregion
	}
	//endregion

	//region 修改分红间隔(分钟)
	@ResponseBody
	@RequestMapping(value="platform/changetemporary", method = RequestMethod.POST, produces="text/html;charset=UTF-8")
	public String changetemporary (HttpServletRequest request  ,String proportion) {
		
		//region 后台安全检测
		if (Double.valueOf(proportion) < 0) 
			return "个人临时奖池增加比例大于0";
		try {
			ButlerExcelFieldGetRequest req = new ButlerExcelFieldGetRequest();
			req.ZoneId = (Integer)request.getSession().getAttribute("ZoneId");
			req.FieldString = "[[\"Platform/Global.xlsx\",1,\"PrizePoolShareBonusAdditionRate\"]]";
			ButlerExcelFieldGetResponse rsp = new ButlerExcelFieldGetResponse();
			if (req.ZoneId < 0)
				client.ServerUrl = "http://api2.qq1798.com:8000/router/rest";
			client.Execute(req, rsp);
			if (!(rsp.ErrMsg ==  null || rsp.ErrMsg == "")) 
				return "获取值错误 ";
		} catch (Exception e) {
			e.printStackTrace();
		}
		//endregion
		//region 设置值
		ButlerExcelFieldSetRequest req = new ButlerExcelFieldSetRequest();
		req.ZoneId = (Integer)request.getSession().getAttribute("ZoneId");
		req.FieldString = "[[\"Platform/Global.xlsx\",1,\"PrizePoolShareBonusAdditionRate\"," + proportion + "]]";
		ButlerExcelFieldSetResponse rsp = new ButlerExcelFieldSetResponse();
		if (req.ZoneId < 0)
			client.ServerUrl = "http://api2.qq1798.com:8000/router/rest";
		client.Execute(req, rsp);
		if (rsp.ErrMsg ==  null || rsp.ErrMsg == "")
			return "success";
		else
			return rsp.ErrMsg;
		//endregion
	}
	//endregion

	//region 游戏排行榜等开关
	@ResponseBody
	@RequestMapping(value="game/switchsetting", method = RequestMethod.POST, produces="text/html;charset=UTF-8")
	public String switchsetting (HttpServletRequest request  ,String Rank, String Arena) {
		System.out.println(Rank + " " + Arena);
		try {
			ButlerExcelFieldGetRequest req = new ButlerExcelFieldGetRequest();
			req.ZoneId = (Integer)request.getSession().getAttribute("ZoneId");
			req.FieldString = "[[\"Client/Global.xlsx\",1,\"RankClose\"],[\"Platform/Global.xlsx\",1,\"RankClose\"],[\"Client/Global.xlsx\",1,\"ArenaSwitch\"],[\"Platform/Global.xlsx\",1,\"ArenaSwitch\"]]";
			System.out.println(req.FieldString);
			ButlerExcelFieldGetResponse rsp = new ButlerExcelFieldGetResponse();
			if (req.ZoneId < 0)
				client.ServerUrl = "http://api2.qq1798.com:8000/router/rest";
			client.Execute(req, rsp);
			if (!(rsp.ErrMsg ==  null || rsp.ErrMsg == "")) 
				return "获取值错误 ";
		} catch (Exception e) {
			e.printStackTrace();
		}
		ButlerExcelFieldSetRequest req = new ButlerExcelFieldSetRequest();
		req.ZoneId = (Integer)request.getSession().getAttribute("ZoneId");
		req.FieldString = "[[\"Client/Global.xlsx\",1,\"RankClose\"," + Rank + "],[\"Platform/Global.xlsx\",1,\"RankClose\"," + Rank + "],[\"Client/Global.xlsx\",1,\"ArenaSwitch\"," +  Arena  + "],[\"Platform/Global.xlsx\",1,\"ArenaSwitch\"," + Arena +"]]";
		System.out.println(req.FieldString);
		ButlerExcelFieldSetResponse rsp = new ButlerExcelFieldSetResponse();
		if (req.ZoneId < 0)
			client.ServerUrl = "http://api2.qq1798.com:8000/router/rest";
		client.Execute(req, rsp);
		if (rsp.ErrMsg ==  null || rsp.ErrMsg == "")
			return "success";
		else
			return rsp.ErrMsg;
	}
	//endregion
	
	//region 游戏内等开关
	@ResponseBody
	@RequestMapping(value="game/switchfishsetting", method = RequestMethod.POST, produces="text/html;charset=UTF-8")
	public String switchfishsetting (HttpServletRequest request  ,String IsFishBossClose) {
		try {
			ButlerExcelFieldGetRequest req = new ButlerExcelFieldGetRequest();
			req.ZoneId = (Integer)request.getSession().getAttribute("ZoneId");
			req.FieldString = "[[\"Fishing/FishGlobal.xlsx\",1,\"IsFishBossClose\"],[\"Client/FishGlobal.xlsx\",1,\"IsFishBossClose\"]]";
			ButlerExcelFieldGetResponse rsp = new ButlerExcelFieldGetResponse();
			if (req.ZoneId < 0)
				client.ServerUrl = "http://api2.qq1798.com:8000/router/rest";
			client.Execute(req, rsp);
			if (!(rsp.ErrMsg ==  null || rsp.ErrMsg == "")) 
				return "获取值错误 ";
		} catch (Exception e) {
			e.printStackTrace();
		}
		ButlerExcelFieldSetRequest req = new ButlerExcelFieldSetRequest();
		req.ZoneId = (Integer)request.getSession().getAttribute("ZoneId");
		req.FieldString = "[[\"Fishing/FishGlobal.xlsx\",1,\"IsFishBossClose\"," + IsFishBossClose + "],[\"Fishing/FishGlobal.xlsx\",1,\"IsFishBossClose\"," + IsFishBossClose + "]]";
		ButlerExcelFieldSetResponse rsp = new ButlerExcelFieldSetResponse();
		if (req.ZoneId < 0)
			client.ServerUrl = "http://api2.qq1798.com:8000/router/rest";
		client.Execute(req, rsp);
		if (rsp.ErrMsg ==  null || rsp.ErrMsg == "")
			return "success";
		else
			return rsp.ErrMsg;
	}
	//endregion
	
	//region 获取当前游戏的状态
	@ResponseBody
	@RequestMapping(value="game/switchfishgetting", method = RequestMethod.POST, produces="text/html;charset=UTF-8")
	public JSONObject switchfishgetting (HttpServletRequest request) {
		//将返回数据存储到json里
		JSONObject json = new JSONObject();
		try {
			ButlerExcelFieldGetRequest req = new ButlerExcelFieldGetRequest();
			req.ZoneId = (Integer)request.getSession().getAttribute("ZoneId");
			req.FieldString = "[[\"Platform/Global.xlsx\",1,\"RankClose\"],[\"Platform/Global.xlsx\",1,\"ArenaSwitch\"],[\"Fishing/FishGlobal.xlsx\",1,\"IsFishBossClose\"]]";
			ButlerExcelFieldGetResponse rsp = new ButlerExcelFieldGetResponse();
			if (req.ZoneId < 0)
				client.ServerUrl = "http://api2.qq1798.com:8000/router/rest";
			client.Execute(req, rsp);
			//将请求返回值存储到String数组当中
			List list = new ArrayList<Object>();
			for (int i = 0;i < rsp.Content.length();i++) {
				//判断当前字符是否是数字，如果是，则存入数组
				if(Character.isDigit(rsp.Content.charAt(i))) {
					list.add(rsp.Content.charAt(i));
				}
			}
			//处理返回数据
			try {
				json.put("RankSwitch", list.get(0));
				json.put("ArenaSwitch", list.get(1));
				json.put("FishBossSwitch", list.get(2));
			} catch (Exception e) {
				e.printStackTrace();
			}
			
			if (!(rsp.ErrMsg ==  null || rsp.ErrMsg == "")) {
				json.put("message", rsp.ErrMsg);
				return json;
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
		return json;
	}
	//endregion

	//region table表改变传回后端数据
	@ResponseBody
	@RequestMapping(value="game/setCustom", method = RequestMethod.POST, produces="text/html;charset=UTF-8")
	public JSONObject setCustom(HttpServletRequest request,String data) {
		JSONObject json = JSON.parseObject(JSON.parseObject(data)
				.get("cache").toString()).getObject("AllTable",JSONObject.class);
		StringBuilder sb = new StringBuilder();
		JSONObject jsondata = new JSONObject();
		JSONArray array = new JSONArray();
		for(int i = 0;i < json.size();i++) {
			if (!(json.get("data" +  i).toString().equals("[]"))) {
				JSONArray array2 = new JSONArray();
				array2.add(0, json.getObject("data" +  i, JSONObject.class).getString("title"));
				array2.add(1, json.getObject("data" +  i, JSONObject.class).getString("channel"));
				array2.add(2, json.getObject("data" +  i, JSONObject.class).getString("number"));
				json.getObject("data" +  i, JSONObject.class);
				array.add(array2);
			}
		}
		sb.append("[[\"Client/Global.xlsx\",1,\"MallAgentInfoList\",\"");
		sb.append(array.toString().replace("\"", "\\\""));
		sb.append("\"]]");
		ButlerExcelFieldSetRequest req = new ButlerExcelFieldSetRequest();
		ButlerExcelFieldSetResponse rsp = new ButlerExcelFieldSetResponse();
		req.ZoneId = (Integer)request.getSession().getAttribute("ZoneId");
		req.FieldString = sb.toString();
		if (req.ZoneId < 0)
			client.ServerUrl = "http://api2.qq1798.com:8000/router/rest";
		client.Execute(req, rsp);
		if (rsp.ErrMsg == null) {
			jsondata.put("status", "200");
		}else {
			jsondata.put("status", "201");
		}
		jsondata.put("message", rsp.ErrMsg);
		jsondata.put("count", 0);
		jsondata.put("data", 0);
		return jsondata;
	}
	//endregion
   
    
}
